var rtewindow;
var content;
var isIE; 
var ua      = navigator.userAgent.toLowerCase(); 
isIE        = ((ua.indexOf("msie")     != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));  

function openArea( divid )
{
	var d = document.getElementById( divid );

	d.style.display = 'block';
	return 'open';
}

function get_content()
{
	if( document.getElementById('ed-0_wysiwyg_used').value == 0 )
	{
		content = document.getElementById('ed-0_textarea').value;
	}
	else
	{
		content = document.getElementById('ed-0_textarea').value;
	}
}

function article_preview()  
{
	openArea('preview_box');
	get_content();
	var arr_content = new Array(); 
	arr_content['preview'] = content; 
	var req = new ajax_request();  
	req.xml_init();  
	req.show_loading( 'Loading preview...' );  
	var ret = function()   
	{  
		if( req.readystate_ready_and_ok() )  
		{  
			req.hide_loading();  
			var dyn = document.getElementById('test_preview');  
			dyn.innerHTML = req.xmlhandler.responseText;  
		}  
	}  
	req.onreadystatechange( ret );  
	req.process( ipb_var_base_url+"autocom=ineo&mod=article&op=preview", "POST" , req.format_for_post(arr_content) );  
}

function toggleArea( divid )
{
	var d = document.getElementById( divid );

	if( d.style.display == null || d.style.display == 'none' )
	{
		d.style.display = 'block';
		return 'open';
	}
	else
	{
		d.style.display = 'none';
		return 'closed';
	}
}

function openArea( divid )
{
	var d = document.getElementById( divid );

	d.style.display = 'block';
	return 'open';
}

function currentAttach()
{
	var isOpen = toggleArea('current_frame');

	if( isOpen == 'closed' )
	{
		return 0;
	}

	var req = new ajax_request();
	req.xml_init();

	req.show_loading( 'Loading Attachments...' );

	var ret = function() 
	{
		if( req.readystate_ready_and_ok() )
		{
			req.hide_loading();
			var dyn = document.getElementById('current_attachments');
			dyn.innerHTML = req.xmlhandler.responseText;
		}
	}

	req.onreadystatechange( ret );

	req.process( ipb_var_base_url+"autocom=ineo&mod=xml&op=attachments&id="+article_id, "GET" , "" );

}

function postUploadAttach(att_id)
{
	var isOpen = openArea('current_frame');

	var req = new ajax_request();
	req.xml_init();
	req.show_loading( 'Loading Attachments...' );
	var ret = function() 
	{
		if( req.readystate_ready_and_ok() )
		{
			req.hide_loading();
			var dyn = document.getElementById('current_attachments');
			dyn.innerHTML = req.xmlhandler.responseText;
		}
	}
	req.onreadystatechange( ret );
	req.process( ipb_var_base_url+"autocom=ineo&mod=xml&op=attachments&id="+att_id, "GET" , "" );
}

function deleteAttach( att_id, att_span )
{
	var req = new ajax_request();
	req.xml_init();
	req.show_loading( 'Deleting Attachment...' );
	var ret = function() 
	{
		if( req.readystate_ready_and_ok() )
		{
			req.hide_loading();
			var dyn = document.getElementById(att_span);
			dyn.innerHTML = req.xmlhandler.responseText;
		}
	}
	req.onreadystatechange( ret );
	req.process( ipb_var_base_url+"autocom=ineo&mod=xml&op=attach_delete&id="+att_id, "GET" , "" );
}